bouncing = [];
var pi = {
    SelectAll: function (chkAll) {
        var items = $("input[type='checkbox']");
        for (i = 0; i < items.length; i++) {
            if (items[i].type == "checkbox" && (items[i].name == "processing" || items[i].name == 'disabled') && !items[i].disabled) {
                items[i].checked = chkAll.checked
            }
        }
    }, DelCallback: function () {
        var val;
        $("input:checkbox[name='processing']:checked").each(function () {
            val = $(this).val();
            $('.del' + val).remove();
            pi.Detect()
        })
    }, Del: function (m) {
        var len, count, i = 0;
        len = $("input:checkbox[name='processing']:checked").length;
        count = parseInt($('#Selcount').html());
        if (len > 0) {
            var m = m || '您确定要删除吗?';
            layer.confirm('<h4 class="mt0 mb4"><b>删除确认</b></h4><p>' + m + '</p>', {btn: ['确 定', '取 消']}, function (index) {
                x.close(index);
                if (len === 1) {
                    var val = $("input:checkbox[name='processing']:checked").val();
                    ajax_Del(val);
                    count--
                } else {
                    var toval = '';
                    $("input:checkbox[name='processing']:checked").each(function () {
                        toval += $(this).val() + ',';
                        count--
                    });
                    ajax_DelLot(toval)
                }
                pi.DelCount(count)
            })
        } else {
            x.msg('请先选择需要批量操作的数据')
        }
    }, DelAll: function (m) {
        if (parseInt($('#Selcount').html()) > 0) {
            var m = m || '您确定要删除吗?';
            layer.confirm('<h4 class="mt0 mb4"><b>删除确认</b></h4><p>' + m + '</p>', {btn: ['确 定', '取 消']}, function (index) {
                x.close(index);
                ajax_DelAll()
            })
        } else {
            x.msg('没有数据可以删除')
        }
    }, Detect: function () {
        if ($(".processing").length < 1 && parseInt($('#Selcount').html()) > 1) {
            var page = parseInt($('#Selpage').html());
            var pages = parseInt($('#Selpages').html());
            if (page > pages) {
                $('#Selpage').html(page - 1)
            }
            setTimeout(function () {
                ajax_html(0)
            }, 500)
        }
    }, DelCount: function (u) {
        $('#Selcount').html(u);
        page.SelCount()
    }
};
var page = {
    SelPage: function (p) {
        var page = parseInt($('#Selpage').html());
        var pages = parseInt($('#Selpages').html());
        if (p == 'first') {
            $('#Selpage').html(1);
            if (page <= 1) {
                x.msg('已经是第一页了');
                return false
            }
        } else if (p == 'up') {
            if (page <= 1) {
                $('#Selpage').html(1);
                x.msg('已经是第一页了');
                return false
            }
            $('#Selpage').html(page - 1)
        } else if (p == 'down') {
            if (page >= pages) {
                $('#Selpage').html(pages);
                x.msg('已经是最后一页了');
                return false
            }
            $('#Selpage').html(page + 1)
        } else {
            $('#Selpage').html(pages);
            if (page >= pages) {
                x.msg('已经是最后一页了');
                return false
            }
        }
        ajax_html(0)
    }, SelCount: function () {
        var count = parseInt($('#Selcount').html());
        var pnum = parseInt($("#Selpagenum option:selected").val());
        if (!count) {
            $("#Selpages").html(1)
        } else if (pnum == 3) {
            $("#Selpages").html(Math.ceil(count / 100))
        } else if (pnum == 2) {
            $("#Selpages").html(Math.ceil(count / 50))
        } else if (pnum == 1) {
            $("#Selpages").html(Math.ceil(count / 20))
        } else {
            $("#Selpages").html(Math.ceil(count / 12))
        }
    }, SelSetNum: function (e, k) {
        $('#Selpage').html(1);
        x.ajax('/Ajax/Index/setpagenum', 'act=' + k + '&val=' + e.value, '', 1);
        page.SelCount()
    }, SelSetCount: function (u) {
        $('#Selpage').html(1);
        $('#Selcount').html(u);
        page.SelCount()
    }, SelSetCount1: function () {
        $('#Selpage').html(1)
    }, Getpage: function () {
        return $('#Selpage').html()
    },
};
var x = {
    postData: function (_url, _data, _loid, _type, _time, _datartpe, _suss, _error) {
        var loid = _loid !== 1 ? x.loading(_loid) : '';
        xhr = $.ajax({
            type: _type || 'POST',
            url: _url.indexOf('?') === -1 ? _url + '?r=' + Math.random(1) : _url + '&r=' + Math.random(1),
            async: true,
            dataType: _datartpe || 'HTML',
            timeout: _time || 60000,
            data: _data,
            success: function (d) {
                if (!d || d == "") {
                    x.btn('操作失败', '系统没有回应内容');
                    return false
                }
                if (_suss) {
                    _suss(d)
                } else {
                    $("#ajaxshow").html(d);
                    return false
                }
            },
            error: function (error, errorType) {
                if (_error) {
                    _error(error)
                } else {
                    if (errorType == 'timeout') {
                        x.btn('链接超时，请重试!')
                    } else {
                        x.btn('操作失败，请重试!')
                    }
                    return false
                }
            },
            complete: function () {
                if (_loid !== 1) x.close(loid)
            }
        })
    }, ajax: function (u, d, m, l, t) {
        if (m) {
            t = t || '操作确认';
            return layer.open({
                content: '<h4 class="mt0 mb3">' + t + '</h4><p>' + m + '</p>',
                btn: ['确定', '取消'],
                shadeClose: false,
                yes: function (index) {
                    x.close(index);
                    x.postData(u, d, l)
                }
            })
        } else {
            x.postData(u, d, l)
        }
    }, select: function (t, d, u, m, l) {
        x.ajax(u, 'key=' + d + '&val=' + t.value, m, l)
    }, del: function (u, d, m, l) {
        m = m || '您确定要删除吗?';
        return layer.open({
            content: '<h4 class="mt0 mb3">删除确认</h4><p>' + m + '</p>',
            btn: ['确定', '取消'],
            shadeClose: false,
            yes: function (index) {
                x.close(index);
                x.postData(u, d, l)
            }
        })
    }, msg: function (m, t) {
        t = t || 2;
        layer.open({content: m, shade: 'background-color: rgba(0,0,0,0)', shadeClose: true, skin: 'msg', time: t})
    }, loading: function (msg, mod) {
        msg = msg || '';
        mod = mod ? true : false;
        return layer.open({type: 2, content: msg, shadeClose: mod, shade: 'background-color: rgba(0,0,0,0)'})
    }, url: function (u, m) {
        x.loading(m, true);
        window.location.href = u
    }, pjax: function (u, m) {
        x.html(u)
    }, btn: function (t, m, b) {
        if (t && m) {
            m = '<h4 class="mt0 mb3">' + t + '</h4><p>' + m + '</p>'
        } else if (t) {
            m = '<h4>' + t + '</h4>'
        }
        return layer.open({
            content: m, btn: b || '我知道了', shadeClose: false, yes: function (index) {
                x.close(index)
            }
        })
    }, tip: function (m, h) {
        $(".app-main").addClass("o-y-h");
        $(".app-footer").addClass("absolute");
        $(".refresh").addClass("hide relative");
        layer.open({
            shade: true,
            shadeClose: true,
            anim: 'scale',
            content: m,
            style: 'width:7.1rem;',
            end: function (index) {
                $(".app-main").removeClass("o-y-h");
                $(".app-footer").removeClass("absolute");
                $(".refresh").removeClass("hide relative")
            }
        })
    }, close: function (i) {
        if (typeof (i) === 'number') {
            layer.close(i)
        } else {
            layer.closeAll()
        }
    }, mclose: function (i) {
        var len, index;
        if (i === 0) {
            x.close()
        } else if (i) {
            $('#layui-m-layer' + i + ' .layui-m-layerchild').addClass('layui-m-anim-close');
            $('#layui-m-layer' + i + ' .layui-m-layershade').addClass('close');
            setTimeout(function () {
                layer.close(i)
            }, 300)
        } else {
            len = $(".layui-m-layer").length;
            if (len == 1) {
                index = $(".layui-m-layer").attr('index');
                if ($(".layui-m-layer").is('.layui-m-layer1')) {
                    x.mclose(index)
                } else {
                    layer.close(index)
                }
            } else if (len > 1) {
                $(".layui-m-layer").each(function (i) {
                    if (i >= len - 1) {
                        index = $(this).attr('index');
                        if ($(this).is('.layui-m-layer1')) {
                            x.mclose(index)
                        } else {
                            layer.close(index)
                        }
                    }
                })
            } else {
                x.close()
            }
        }
    }, form: function (u, f, i, l) {
        var d;
        f = f || 'formid';
        d = $('#' + f).serialize();
        if (i) {
            x.gethtml(u, d, i, l, 0, "加载失败，请稍后重试!")
        } else {
            x.ajax(u, d, '', l)
        }
    }, gethtml: function (u, i, l, m, e) {
        i = i || 'bodyhtml';
        x.postData(u, '', l, 'GET', '', '', function (data) {
            if (data.substring(0, 7) === '<script') {
                $("#ajaxshow").html(data)
            } else if (m) {
                $("#" + i).append(data)
            } else {
                $("#" + i).html(data)
            }
            return false
        }, function (data) {
            if (e) $("#" + i).html("<p style='text-align: center;margin:0.5rem auto;'><b>" + e + "</b></p>");
            x.btn('加载失败，请稍后重试!')
        })
    }, mode: function (u, n, s, h, c) {
        var sh, an, st;
        s = s || 'up';
        c = c ? true : false;
        an = (s == 'up') ? 'bottom' : 'top';
        if (h == 1) {
            sh = true;
            st = 'position:absolute; left:0; ' + an + ':0; width:7.5rem;'
        } else {
            sh = 'background-color: rgba(0,0,0,0)';
            st = 'position:absolute; left:0; top:0; bottom:0; width:7.5rem; background-color: hsl(0,0%,97%);'
        }
        x.postData(u, '', 0, 'GET', '', '', function (data) {
            if (data.substring(0, 7) === '<script') {
                $("#ajaxshow").html(data)
            } else {
                $(".app-content").addClass("o-y-h");
                $(".app-footer").addClass("absolute");
                $(".refresh").addClass("hide relative");
                bouncing[n] = layer.open({
                    type: 1,
                    shade: sh,
                    shadeClose: c,
                    anim: s,
                    content: '<div id="mode' + n + '">' + data + '</div>',
                    style: st,
                    end: function (index) {
                        $(".app-content").removeClass("o-y-h");
                        $(".app-footer").removeClass("absolute");
                        $(".refresh").removeClass("hide relative");
                        if (h == 2) {
                            saoma.cleartime()
                        }
                    }
                })
            }
        }, function (data) {
            x.btn('网络异常', '调用窗口失败，请稍后重试!')
        })
    }, mode2: function (u, n, h) {
        x.postData(u, '', 0, 'GET', '', '', function (data) {
            if (data.substring(0, 7) === '<script') {
                $("#ajaxshow").html(data)
            } else {
                $(".app-content").addClass("o-y-h");
                $(".app-footer").addClass("absolute");
                $(".refresh").addClass("hide relative");
                bouncing[n] = layer.open({
                    shade: true,
                    shadeClose: true,
                    anim: 'scale',
                    content: data,
                    style: 'width:7.1rem; max-height:8rem; overflow-y:scroll;',
                    end: function (index) {
                        $(".app-content").removeClass("o-y-h");
                        $(".app-footer").removeClass("absolute");
                        $(".refresh").removeClass("hide relative")
                    }
                })
            }
        }, function (data) {
            x.btn('网络异常', '调用窗口失败，请稍后重试!')
        })
    }, shop: function (url, zfid) {
        var num = trim($('#rmb').val());
        if (num == null || num == 0) {
            $('#rmb').focus();
            return false
        } else if (num[0] == '.') {
            x.msg("金额不能以点开头，请重新填写!");
            return false
        } else if (num < 0.1) {
            x.msg("充值的金额最低不能低于0.1元!");
            return false
        } else if (num > 99999) {
            x.msg("单次充值金额最高不能超过99999元!");
            return false
        }
        x.ajax(url, 'num=' + num + '&zfid=' + zfid)
    }, htmltop: function (i, m) {
        $(i).scrollTo({toT: 0})
    }, int: function (t, i, n) {
        var baval, keyCode;
        n = n || 11;
        baval = $(t).val();
        keyCode = event.which;
        if (i) {
            if (keyCode == 46) {
                if (baval.length < 1 || baval.indexOf(".") >= i) {
                    return false
                } else {
                    return true
                }
            }
        }
        if (keyCode >= 48 && keyCode <= 57) {
            if (baval.length < n) {
                return true
            }
        }
        return false
    }, rem2px: function (d) {
        var val = parseFloat(d) * rem;
        val = val.toFixed(5);
        if (typeof d === 'string' && d.match(/rem$/)) {
            val += 'px'
        }
        return val
    }, px2rem: function (d) {
        var val = parseFloat(d) / rem;
        val = val.toFixed(5);
        if (typeof d === 'string' && d.match(/px$/)) {
            val += 'rem'
        }
        return val
    }, swiperlistleft: function () {
        new Swiper('.swiper-container', {
            slidesPerView: 'auto',
            spaceBetween: 0,
            freeMode: true,
            freeModeSticky: true,
            resistance: true,
        })
    }, refreshBox: function (t, m, f, p, u) {
        refreshBox = new PullToRefresh({
            container: t, pull: {
                set: p, callback: function () {
                    loadpage = 1;
                    setTimeout(function () {
                        $(m).html("");
                        refreshBox.endPullRefresh(true)
                    }, 1000)
                }
            }, up: {
                set: u, callback: function () {
                    f()
                }
            }
        })
    }, getcookie: function (name) {
        var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
        if (arr = document.cookie.match(reg)) {
            return unescape(arr[2])
        } else {
            return null
        }
    }, html: function (_url, _time, _type) {
        var loid = x.loading();
        xhr = $.ajax({
            type: _type || 'GET',
            url: _url.indexOf('?') === -1 ? _url + '?r=' + Math.random(1) : _url + '&r=' + Math.random(1),
            async: true,
            dataType: 'HTML',
            timeout: _time * 1000 || 30000,
            success: function (data) {
                if (data.substring(0, 7) === '<script') {
                    $("#ajaxshow").html(data)
                } else {
                    $("#container").html(data)
                }
            },
            error: function (error, errorType) {
                if (errorType == 'timeout') {
                    x.btn('加载页面超时，请重试!')
                } else if (errorType != 'abort') {
                    x.btn('加载页面失败，请重试!')
                }
            },
            complete: function () {
                x.close(loid)
            }
        })
    }, GetLength: function (str) {
        return str.replace(/[\u0391-\uFFE5]/g, "aa").length
    }, tongzhi: function (num) {
        if ($(".tongzhi").length > 0) {
            var htmllen = x.GetLength($('.tongzhi > p').text());
            var lenceil = Math.ceil(htmllen / 8);
            $(".tongzhi > p").css("width", lenceil + "rem");
            if (lenceil > 6) {
                $(".tongzhi > p").addClass("textleft");
                if (lenceil < 10) lenceil = 10;
                if (lenceil > 20) lenceil = lenceil - 4;
                if (lenceil > 30) lenceil = lenceil - 4;
                $(".tongzhi > p").css("animation-duration", lenceil + "s")
            }
        }
    }
};
var saoma = {
    img: function (qrsig, loginsig, img64) {
        $('#loginmsg').html('等待扫描二维码');
        $("#qrimg").attr("qrsig", qrsig);
        $("#qrimg").attr("loginsig", loginsig);
        $("#qrimg").html("<img src='data:image/png;base64," + img64 + "'/>");
        if (typeof interval == "undefined") {
            interval = setInterval(saoma.loginload, 1000)
        }
    }, qrpic: function (u, d) {
        $('#loginmsg').html('正在获取二维码，请稍等');
        x.ajax(u, d)
    }, qrlogin: function (u, d) {
        if ($("#qrimg").length > 0) {
            var qrsig = $('#qrimg').attr('qrsig');
            var loginsig = $('#qrimg').attr('loginsig');
            x.ajax(u, d + '&qrsig=' + decodeURIComponent(qrsig) + '&loginsig=' + decodeURIComponent(loginsig), '', 1)
        }
    }, loginload: function () {
        if ($("#qrimg").length > 0) {
            var loadh = $('#loginload').html();
            if (loadh.length > 2) {
                loadh = ''
            } else {
                loadh += '·'
            }
            $('#loginload').html(loadh)
        } else {
            saoma.cleartime()
        }
    }, cleartime: function () {
        if (typeof interval != "undefined") {
            clearInterval(interval);
            delete interval
        }
    }
};
var Stor = {
    get: function (name) {
        return sessionStorage.getItem(name)
    }, add: function (name, val) {
        sessionStorage.setIten(name, val);
        return
    }, del: function (name) {
        sessionStorage.removeItem(name);
        return
    },
};
$(document).on('click', '[data-conid] a,a[data-conid]', function () {
    var _this = $(this);
    var btnid = _this.parent().parent().attr('data-conid') || 'buttoncon';
    var con = _this.text();
    $('#' + btnid).text(con)
});

function trim(str) {
    return str.replace(/(^\s*)|(\s*$)/g, "")
};var ScrollFix = function (elem) {
    var startY, startTopScroll;
    elem = elem || document.querySelector(elem);
    if (!elem) return;
    elem.addEventListener('touchstart', function (event) {
        startY = event.touches[0].pageY;
        startTopScroll = elem.scrollTop;
        if (startTopScroll <= 0) elem.scrollTop = 1;
        if (startTopScroll + elem.offsetHeight >= elem.scrollHeight) elem.scrollTop = elem.scrollHeight - elem.offsetHeight - 1
    }, false)
};
(function (win) {
    var docEl = win.document.documentElement;
    var dpr = 1;
    var tid;
    var designPixel = 750;

    function refreshRem() {
        var width = docEl.getBoundingClientRect().width;
        rem = width / (designPixel / 100);
        docEl.style.fontSize = rem + 'px'
    }

    win.addEventListener('resize', function () {
        clearTimeout(tid);
        tid = setTimeout(refreshRem, 500)
    }, false);
    refreshRem()
})(window);
$(document).on('click', '.dropdown-menu,.dropdown-desc', function () {
    if ($(this).is('.dropdown-desc')) {
        $(".dropdown").removeClass("open");
        $(".dropdown-desc").addClass("on");
        setTimeout(function () {
            $(".dropdown-desc").removeClass("open on")
        }, 100)
    } else if ($(this).is('.dropdown-menu')) {
        $(".dropdown-desc").toggleClass("open");
        $(this).parent().toggleClass("open")
    }
});
$(document).on('click', '.dropdown-list', function () {
    $(".dropdown").removeClass("open");
    $(".dropdown-desc").addClass("on");
    setTimeout(function () {
        $(".dropdown-desc").removeClass("open on")
    }, 100)
});
$.fn.scrollTo = function (options) {
    var defaults = {toT: 0, durTime: 100, delay: 30, callback: null};
    var opts = $.extend(defaults, options), timer = null, _this = this, curTop = _this.scrollTop(),
        subTop = opts.toT - curTop, index = 0, dur = Math.round(opts.durTime / opts.delay),
        smoothScroll = function (t) {
            index++;
            var per = Math.round(subTop / dur);
            if (index >= dur) {
                _this.scrollTop(t);
                window.clearInterval(timer);
                if (opts.callback && typeof opts.callback == 'function') {
                    opts.callback()
                }
                return
            } else {
                _this.scrollTop(curTop + index * per)
            }
        };
    timer = window.setInterval(function () {
        smoothScroll(opts.toT)
    }, opts.delay);
    return _this
};
if (("standalone" in window.navigator) && window.navigator.standalone) {
    var noddy;
    $(document).on('click', 'a', function (event) {
        noddy = event.target;
        while (noddy.nodeName !== "A" && noddy.nodeName !== "HTML") {
            noddy = noddy.parentNode
        }
        if ('href' in noddy && noddy.href.indexOf('http') !== -1) {
            event.preventDefault();
            layer.open({type: 2, time: 2, shadeClose: true, shade: 'background-color: rgba(0,0,0,0)'});
            document.location.href = noddy.href
        }
    })
}
;